from django.db import models

from member.models import Member


# Create your models here.
class Loan(models.Model):
    member = models.ForeignKey(Member)
    surety = models.ForeignKey(Member, related_name='member_temps')
    amount_borrowed = models.IntegerField('Loan Amount', max_length=20, null=False)
    rate = models.IntegerField('Loan Rate', max_length=20, null=False)
    loan_duration = models.IntegerField('Repayment Period (Months)', max_length=20, null=False)
    date_of_issue = models.DateField('Date of Issue', auto_now_add=True, null=False)
    date_of_firstInstallment = models.DateField('First Installment')

    class Meta:
        db_table = 'loans'
        ordering = ['date_of_issue']

    def borrower(self):
        return u'%s %s' %(self.member.first_name, self.member.last_name)

    def __unicode__(self):
        return self.amount_borrowed
    